home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Bitmap Libraries 2.0
/
Examples
/
Rotation
/
BitMap.h
< prev
next >
Wrap
Text File
|
1996-07-08
|
8KB
|
294 lines
/* File BitMap.h Copyright (C) 1996 by John R. Montbriand. All Rights Reserved. */
#ifndef __BITMAP__
#define __BITMAP__
/* File BitMap.h
Copyright (C) 1996 by John Montbriand. All Rights Reserved.
Distribute freely in areas where the laws of copyright apply.
Use at your own risk.
Do not distribute modified copies.
These various BitMap libraries are for free!
See the file BitMap.txt for details.
*/
#include <Types.h>
#include <QuickDraw.h>
#ifdef __cplusplus
extern "C" {
#endif
/* version number for this implementation */
#define kBitMapVersion 2
/* NewBitMap creates a new bitmap pointer with the requested
dimensions. The raster data is initialized to zeros and the
returned pointer is unlocked. If there is not enough memory
to allocate the bitmap, NewBitMap will return NULL. Initially,
the baseAddr field is set to NULL. */
BitMap* NewBitMap(short width, short height);
/* KillBitMap disposes of a bitmap pointer allocated by one of:
NewMacPaintBitMap, NewBitMap, RotateRight, RotateLeft, FlipVertical,
FlipHorizontal, RotateBitMap, DuplicateBitMap, PaintBucketBitMap,
LassoBitMap, PICTToBitMap, BitMapAND, BitMapOR, BitMapXOR,
BitMapNOT, or StringToBitMap.
It's your general all purpose bitmap pointer disposal function. */
void KillBitMap(BitMap* bits);
/* RotateRight creates a new bitmap containing the image
stored in the parameter bitmap pointer rotated 90 degrees
to the right. The resulting bitmap is appropriately sized:
i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
then the result bitmap pointer will be 200 pixels wide and 100
pixels tall. */
BitMap* RotateRight(BitMap* bits);
/* RotateLeft creates a new bitmap containing the image
stored in the parameter bitmap pointer rotated 90 degrees
to the left. The resulting bitmap is appropriately sized:
i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
then the result bitmap pointer will be 200 pixels wide and 100
pixels tall. */
BitMap* RotateLeft(BitMap* bits);
/* FlipVertical creates a new bitmap containing the image
stored in the parameter bitmap pointer flipped upside
down. The resulting bitmap will be the same size as
the original image. */
BitMap* FlipVertical(BitMap* bits);
/* FlipHorizontal creates a new bitmap containing the image
stored in the parameter bitmap pointer flipped horizontally.
The resulting bitmap will be the same size as the original image. */
BitMap* FlipHorizontal(BitMap* bits);
/* RotateBitMap creates a new bitmap containing the image from
the parameter bitmap pointer rotated angle degrees about the
center (cx, cy). The resultant bitmap will have the same dimensions
as the parameter bitmap regardless of the angle specified. */
BitMap* RotateBitMap(BitMap* bits, short cx, short cy, float angle);
/* IRotateBitMap is identical to RotateBitMap except it accepts an
integer variable in the angle parameter. */
BitMap* iRotateBitMap(BitMap* bits, short cx, short cy, short angle);
/* DuplicateBitMap creates a copy of the bitmap parameter. */
BitMap* DuplicateBitMap(BitMap* bits);
/* PaintBucketBitMap works like the paint bucket tool found in
most graphical applications. It calls the routine SeedFill
and to fill in the image information in the resulting bitmap
pointer. */
BitMap* PaintBucketBitMap(BitMap* bits, short h, short v);
/* LassoBitMap works like the lasso bucket tool found in
most graphical applications. It calls the routine CalcMask
and to fill in the image information in the resulting bitmap
pointer. */
BitMap* LassoBitMap(BitMap* bits);
/* TraceBitMap performs the 'trace edges' command found in
many graphical applications returning a new bitmap
containing the traced image. */
BitMap* TraceBitMap(BitMap* bits);
/* EqualBitMaps returns true if the two bitmaps are identical in size
and image content. */
Boolean EqualBitMaps(BitMap* a, BitMap* b);
/* PICTToBitMap creates a new bitmap pointer the using the size
information provided in the QuickDraw picture pointer parameter
and draws the picture in the bitmap before returning the bitmap. */
BitMap* PICTToBitMap(PicHandle pic);
/* BitMapToPICT returns a QuickDraw picture that will draw the
image stored in the bitmap. BitMapToPICT is the inverse
of PICTToBitMap. */
PicHandle BitMapToPICT(BitMap* bits);
/* BitMapAND logically ANDs the raster data of two bitmap pointers
returning a new bitmap pointer containing the result. The two
parameter bitmaps must have identical dimensions. */
BitMap* BitMapAND(BitMap* a, BitMap* b);
/* BitMapOR logically ORs the raster data of two bitmap pointers
returning a new bitmap pointer containing the result. The two
parameter bitmaps must have identical dimensions. */
BitMap* BitMapOR(BitMap* a, BitMap* b);
/* BitMapXOR logically XORs the raster data of two bitmap pointers
returning a new bitmap pointer containing the result. The two
parameter bitmaps must have identical dimensions. */
BitMap* BitMapXOR(BitMap* a, BitMap* b);
/* BitMapNOT returns a new bitmap pointer containing the inverse
of the raster image contained in the bitmap pointer a. */
BitMap* BitMapNOT(BitMap* a);
/* BitMapTest tests the value of the pixel at the location (h,v)
returning true if the pixel is 1, and false if the pixel is zero. */
Boolean BitMapTest(BitMap* bits, short h, short v);
/* BitMapSet sets the value of the pixel at the location (h,v) to 1. */
void BitMapSet(BitMap* bits, short h, short v);
/* BitMapClear clears the value of the pixel at the location (h,v) to 0. */
void BitMapClear(BitMap* bits, short h, short v);
/* BitMapToggle inverts the value of the pixel at the location (h,v)
returning true if the pixel is set to 1 or false if the pixel
is set to 0. */
Boolean BitMapToggle(BitMap* bits, short h, short v);
/* BitMapPort data structure managed by the routines NewBMP
and DisposeBMP. You should never have to access the fields of this
record directly as it's all taken care of by NewBMP and DisposeBMP. */
typedef struct {
GrafPort gp; /* the grafport record for drawing into the bitmap */
GrafPtr gpsave; /* saved grafport for later restoration */
BitMap* bits; /* the bitmap pointer */
} BitMapPort;
/* NewBMP is called by the WithBitMap macro and you should
never have to call it directly yourself. What it does is
it locks the bitmap, saves the original grafport, and creates
a new grafport suitable for drawing into the bitmap. NewBMP
should be followed by a call to DisposeBMP which will restore
the original grafport, unlock the bitmap, and dispose of the
new grafport. */
BitMapPort* NewBMP(BitMap* bits);
/* DisposeBMP unlocks the bitmap pointer passed to NewBMP, deallocates
the grafport allocated for it, and restores the original grafport.
the macro WithBitMap calls this routine automatically and you will
not normally have to call it directly. */
void DisposeBMP(BitMapPort* bmp);
/* WithBitMap is a macro facility that sets up the drawing
environment such that any drawing commands in the statement
following the macro instantiation will draw into the bitmap
provided as the first parameter.
bits is a bitmap pointer: BitMap **bits;
bmp is a bitmap port pointer variable: BitMapPort* bmp; */
#define WithBitMap(bits, bmp) \
for (bmp = NewBMP(bits); bmp != NULL; DisposeBMP(bmp), bmp = NULL)
/* PlotBitMap provides a simple interface for drawing a bitmap in
the current grafport. The bitmap is drawn with the top left corner
aligned with the point (h,v) using the indicated transfer mode. */
void PlotBitMap(BitMap* bits, short h, short v, short mode);
/* StringToBitMap converts the string pointed to by s into a bitmap
drawing the string onto an appropriately sized bitmap for the
given font, size, and style(face). StringToBitMap is useful for
converting strings to bitmap so rotation can be applied with
RotateRight or RotateLeft before it is displayed. StringToBitMap
preserves the current grafport. */
BitMap* StringToBitMap(short font, short size, short face, StringPtr s);
#ifdef __cplusplus
};
#endif
#endif
/* end of File BitMap.h */